﻿using DelonixRegiaSystem.Classes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DelonixRegiaSystem
{
    public partial class Login : Form
    {
        public static string user_name;
        public Login()
        {
            InitializeComponent();
        }

        #region XIAO LING'S CODES
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string username = tbxUsername.Text;
            string pwd = tbxPassword.Text;
            lblErrPass.Visible = false;
            lblErrUser.Visible = false;
            if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(pwd))
            {
                string staffType = DBLogin.LoginValiate(username, pwd);

                if (string.IsNullOrEmpty(staffType))
                {
                    MessageBox.Show("Your username or password is incorrect!");
                    return;
                }

                //use this to redirect to different form 
                if (staffType == "Receptionist")
                {
                    user_name = username;
                    MainMenuStaff objform1 = new MainMenuStaff();

                    this.Hide();
                    objform1.Show();
                }
                else if (staffType == "Admin")
                {
                    user_name = username;
                    AdminMainMenu obiform2 = new AdminMainMenu();
                    this.Hide();
                    obiform2.Show();
                }
                //else if (staffType == "Reception Staff") ;


            }
            else
            {
                if (string.IsNullOrEmpty(username))
                    lblErrUser.Visible = true;
                if (string.IsNullOrEmpty(pwd))
                    lblErrPass.Visible = true;
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        #endregion
    }
}
